/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 5/5/2010
 * Time: 10:20 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using popLib.Resource;

namespace popLib.CustomeControl
{
	/// <summary>
	/// Description of OptionPanel.
	/// </summary>
	public partial class OptionPanel : UserControl
	{
		OptionPanelItem[] panelContainer = new OptionPanelItem[0];
		
		public OptionPanel()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		public OptionPanelItem[] Panel{
			get{
				return panelContainer;
			}
			set{
				panelContainer = value;				
				initInterface();
			}
		}
		
		void initInterface(){
			int counter = 0;
			pnl_container.Controls.Clear();
			flpl_buttonContainer.Controls.Clear();				
			
			foreach( OptionPanelItem panel in panelContainer ){					
				panel.Dock = DockStyle.Fill;
				panel.Tag = counter;
				panel.BackColor = Color.White;
				pnl_container.Controls.Add(panel);
				
				Label label = new Label();
				label.Text = "  "+panel.PanelTitle;				
				label.Size = new Size( 190, 30 );
				label.ForeColor = Color.FromArgb(0,21,110);
				label.Tag = counter;
				label.TextAlign = ContentAlignment.MiddleLeft;
				label.Margin = new Padding( 3 );
				
				if( counter == 0 ){
					label.BackgroundImage = (Bitmap)popLibResource.button_selected;
					flpl_buttonContainer.Text = "0";
				}
				
				label.MouseEnter += delegate(object sender, EventArgs e) {
					if( flpl_buttonContainer.Text != ((Label)sender).Tag.ToString() )
						((Label)sender).BackgroundImage = (Bitmap)popLibResource.button_over;
				};
				
				label.MouseLeave += delegate(object sender, EventArgs e) {
					if( flpl_buttonContainer.Text != ((Label)sender).Tag.ToString() )
						((Label)sender).BackgroundImage = null;
				};
				
				label.Click += delegate(object sender, EventArgs e) { 
					viewPanel( (Label)sender );
				};
				
				flpl_buttonContainer.Controls.Add( label );
				
				counter++;
			}
		}
		
		void viewPanel( Label label ){
			foreach( OptionPanelItem panel in panelContainer ){
				if( panel.Tag.Equals(label.Tag) ){
					//panel.Show();
					panel.BringToFront();
				}else{
					//panel.Hide();
				}
			}
			
			foreach( Label eachLabel in flpl_buttonContainer.Controls ){				
				eachLabel.BackgroundImage = null;				
			}
			
			label.BackgroundImage = (Bitmap)popLibResource.button_selected;			
			flpl_buttonContainer.Text = label.Tag.ToString();
		}
		
		
		
		void Uc_OptionPanelLoad(object sender, EventArgs e)
		{
			initInterface();
		}
	}
	
	public class OptionPanelItem: Panel{
		string panelCommand = "Button Command";
		public string PanelTitle{
			get{ return panelCommand; }
			set{ panelCommand = value; }
		}
	}
}
